igo8, psp: Use new unicode functions of CET lib.
authoroliskoli <oliskoli>
Tue, 24 Jun 2008 22:51:19 +0000 (22:51 +0000)
committeroliskoli <oliskoli>
Tue, 24 Jun 2008 22:51:19 +0000 (22:51 +0000)
igo8.c
psp.c

diff --git a/igo8.c b/igo8.c
index 56ec3515835ebaff47e5d533b7e75cc612e0d49b..c016a88dca825aabee1a632004d9d230dd6a9ccb 100644 (file)
--- a/igo8.c
+++ b/igo8.c
@@ -62,6 +62,8 @@
 #include <ctype.h>
 #include <time.h>
 #include "defs.h"
+#include "cet.h"
+#include "cet_util.h"
 
 #define TRUE 1
 #define FALSE 0
@@ -228,8 +230,26 @@ static void write_igo8_track_point(const waypoint *wpt)
 //
 // Please replace this with a much more filled out and correct version if you see 
 // fit.
-unsigned int ascii_to_unicode_2(char* dst, unsigned int dst_max_length, char* src)
+
+/* 2008/06/24, O.K.: Use CET library for ascii-> unicode 2 converter */
+
+unsigned int ascii_to_unicode_2(char *dst, const int dst_max_length, const char *src)
 {
+#if 1
+       short *unicode;
+       int len;
+
+       unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len);
+
+       len += 1;       /* include terminating null */
+       len *= 2;       /* real size */
+       if (len > dst_max_length) len = dst_max_length;
+       memcpy(dst, unicode, len);
+       
+       xfree(unicode);
+       
+       return len;
+#else
        unsigned int current_src_position = 0;
        unsigned int current_dst_position = 0;
        unsigned short current_unicode_char;
@@ -249,6 +269,7 @@ unsigned int ascii_to_unicode_2(char* dst, unsigned int dst_max_length, char* sr
        }
 
        return current_dst_position;
+#endif
 }
 
 void write_header()
diff --git a/psp.c b/psp.c
index 61d37bbc4ce327ac4d123e857c4ca5b286ef607f..8934b4eb8f364913b07046e6716b5ecfb98c71f5 100644 (file)
--- a/psp.c
+++ b/psp.c
@@ -44,30 +44,17 @@ static void
 psp_write_str(const char *str)
 {
        if (str && *str) {
-               const char *cin = str;
-               gbint16 *tmp, *res;
-               int len = 0;
+               short *unicode;
+               int len;
                
                /* convert UTF-8 string into a unicode sequence */
                /* not perfect, but enough for us */
+               unicode = cet_str_any_to_uni(str, global_opts.charset, &len);
+               if (len > MAXPSPSTRINGSIZE) len = MAXPSPSTRINGSIZE;
+               gbfputc((unsigned char)len, psp_file_out);
+               if (len) gbfwrite(unicode, 2, len, psp_file_out);
 
-               res = tmp = xmalloc(strlen(str) << 1);
-               while (*cin) {
-                       int bytes, value;
-
-                       if (cet_utf8_to_ucs4(cin, &bytes, &value) != CET_SUCCESS)
-                               value = CET_NOT_CONVERTABLE_DEFAULT;
-                       *tmp++ = value;
-                       cin += bytes;
-                       len++;
-                       if (len == (MAXPSPSTRINGSIZE >> 1)) break;
-               }
-               gbfputc(len, psp_file_out);
-               tmp = res;
-               while (len--)
-                       /* ! we need LE values, don't use gbfwrite ! */
-                       gbfputint16(*tmp++, psp_file_out);
-               xfree(res);
+               xfree(unicode);
        }
        else
                gbfputc(0, psp_file_out);